
window.getSelection().empty();
var $tab = $(".tab li");
var id = cookie("ID");
var token = cookie("Token");
var flog = 0;
var res = null;
$("#downShow").css("display", "none");
console.log(id, token);

if (id.length > 0 && token.length > 0) {
  $("#loginBtn").css("display", "none");
  $("#userDropdown").css("display", "block");
  $("#downShow").css("display", "block");

  getUserInfo();
} else {
  $("#loginBtn").css("display", "block");
  $("#userDropdown").css("display", "none");
  $("#downShow").css("display", "none");

}

$("#downShow").click(function () {
  location.href = "./login.html";
  $("#loginBtn").css("display", "block");
  $("#userDropdown").css("display", "none");
});

function getUserInfo() {
  var options = {
    url: "http://localhost:8888/users/info/" + id,
    headers: {
      authorization: token,
    },
  };
  axios(options).then(function (response) {
    console.log(response.data);
    res = response.data;
    $("#nickname").text(res.info.nickname);
    console.log(res.info.nickname);

    if (res.code === 501) {
      $("#loginBtn").css("display", "block");
    }
  });
}
var use = 0;
$("#user").click(function () {
  if (use === 0) {
    $("#downShow").css("display", "block");
    use = 1;
  } else {
    $("#downShow").css("display", "none");
    use = 0;
  }
});


let num = JSON.parse(localStorage.getItem('cart'));
$(".head .shopping-cart .gwc .picer b").html(Object.keys(num).length);